var longestConsecutive = function (nums) {
  let arr = [];
  const allArr = new Map();
  nums = Array.from(new Set([...nums]));
  nums.sort((a, b) => a - b);
  if (nums.length <= 1) return nums.length;
  arr.push(nums[0]);
  for (let i = 1; i < nums.length; i++) {
    let len = arr.length;
    console.log("---1", arr);
    if (arr[len - 1] === nums[i] - 1) {
      arr.push(nums[i]);
      if (i === nums.length - 1) {
        allArr.set(arr, arr);
        break;
      }
    } else {
      allArr.set(arr, arr);
      arr = [nums[i]];
    }
  }
  let max = 0;
  console.log(allArr);
  for (let [key, value] of allArr) {
    max = max > value.length ? max : value.length;
  }
  return max;
};
console.log(longestConsecutive([0, 3, 7, 2, 5, 8, 4, 6, 0, 1]));
